export default function (Vue, options) {

    function getFormData(formData) {
        let data = '';
        for (let key in formData) {
            data += '&' + key + '=' + encodeURIComponent(formData[key] instanceof Object ? JSON.stringify(formData[key]) : formData[key]);
        }
        return data.substring(1);
    }

    var params = {userAccount: null}; //url参数列表
    window.location.search.replace(/[?&]+([^=&]+)=([^&]*)/gi, function (str, key, value) {
        if (/\?userAccount=/.test(value)) { //解决IOS旧版客户端遗留的问题
            let arr = value.split('?userAccount=');
            value = arr[0];
            params.userAccount = arr[1];
        }
        params[key] = value;
    });
    var getToken = params.access_token;
    let inApp = !!getToken;
    var INTERFACE_HOST = 'http://118.178.236.122:9001/selfdriving/api'; //本地调试 使用mock搭建静态数据服务
    var isIos = /ipod|ipad|iphone|mac os x/i.test(navigator.userAgent);

    Date.prototype.format = function (format) {
        var o = {
            "M+": this.getMonth() + 1, //month
            "d+": this.getDate(), //day
            "h+": this.getHours(), //hour
            "m+": this.getMinutes(), //minute
            "s+": this.getSeconds(), //second
            "q+": Math.floor((this.getMonth() + 3) / 3), //quarter
            "S": this.getMilliseconds() //millisecond
        }

        if (/(y+)/i.test(format)) {
            format = format.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
        }

        for (var k in o) {
            if (new RegExp("(" + k + ")").test(format)) {
                format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));
            }
        }
        return format;
    }
    Vue.$AppConfig = Object.assign({
        urlParams: params,
        inApp: inApp,
        isIos: isIos,
        INTERFACE_HOST: INTERFACE_HOST,
        getToken: getToken,
        appJSBridge: function (key, message) {
            if (typeof(window.JsBridge) == 'object' && typeof (window.JsBridge[key]) == 'function') {
                message == undefined ? window.JsBridge[key]() : window.JsBridge[key](message);
                return true;
            } else if (typeof(window.webkit) == 'object') {
                try {
                    message == undefined ? window.webkit.messageHandlers[key].postMessage("") : window.webkit.messageHandlers[key].postMessage(message);
                    return true;
                } catch (e) {
                    console.log(e);
                    return false;
                }
            } else {
                return false;
            }

        }
    }, typeof options === "function" ? options() : options);

}